package service;

import mapper.InvitationMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.Invitation;
import tools.Page;

import javax.annotation.Resource;
import javax.xml.soap.Detail;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/1/4.
 */
@Service("bookService")
public class InvitationServiceImpl implements InvitationService {
    @Resource
    InvitationMapper invitationMapper;
    public Page bookList(@RequestParam("id")Integer id, @RequestParam("name")String name, @RequestParam("pageObj")Page pageObj){
        // 查询总条数
        int totalCount = invitationMapper.getCount();
        // 设置总数、总页数
        pageObj.setTotalCount(totalCount);
        // 如果总条数>0,说明数据库中有数据，再查询具体数据
        if (totalCount > 0) {
            // （用户一直点击下一页）如果当前页大于总页数，把总页数的值赋给当前页的值，显示最后一页的值
            if (pageObj.getCurrPageNo() > pageObj.getTotalPageCount())
                pageObj.setCurrPageNo(pageObj.getTotalPageCount());
            List<Invitation> lrsList = invitationMapper.getInvitationList(id,name,(pageObj.getCurrPageNo()-1)*pageObj.getPageSize(), pageObj.getPageSize());
            System.out.println(lrsList.size()
            );
            pageObj.setList(lrsList);
        } else {
            pageObj.setCurrPageNo(0);
            pageObj.setList(new ArrayList<Invitation>());
        }
        return pageObj;

  }

    @Override
    public int add(Detail detail) {
        return invitationMapper.add(detail);
    }

    @Override
    public Page getInvitationList(Integer chooseId, String choose, Page pageObj) {
        return null;
    }

    @Override
    public Invitation update(int id) {
        return invitationMapper.update(id);
    }

    @Override
    public Invitation getBookList(Integer Invitationid) {
        return null;
    }


}
